#include<iostream>
#include<atomic>

using namespace std;

template<class T>
class MyPtr
{
	T* ptr;
	int* count;
	void release()
	{
		if (--(*count) == 0)
		{
			delete ptr;
			delete count;
		}
	}
public:
	MyPtr(T* _ptr)
		:ptr(_ptr),count(new int(1))
	{}
	~MyPtr()
	{
		if (count)
			release();
	}
	MyPtr(const MyPtr<T>& p)
		:ptr(p.ptr),count(p.count)
	{
		(*count)++;
	}
	void operator=(const MyPtr<T>& p)
	{
		if (this != &p)
		{
			release();
			ptr = p.ptr;
			count = p.count;
			(*count)++;
		}
	}
};

int main()
{
	return 0;
}